/**
 * Created by ZFL on 2017/12/27.
 */
var vm=new Vue({
    el:'#myCash',
    data:{
        userMoney:0,      //用户所有现金币
        recordList:[],    //用户收支记录
    },
    filters:{
      goConver:function(value){
          return divideNumber(value,100)
      }
    }
})
function appInit(){
    PageInit()
}
function PageInit(){
    if(com_obj.userId&&com_obj.userId>0){
        getCashInfo();
        infiniteSroll()
    }else{
        window.location.href='../user/user_login.html'
    }
}
var pageNum=1;
var pageSize=10;
//显示收支记录
function getCashInfo(){
        $.ajaxHandler({
            model:function(){
            var obj={};
            obj.pageNum=pageNum;
            obj.pageSize=pageSize;
            obj.userId=com_obj.userId;
            console.log(obj);
            return obj;
        },
        visibleTime:100,
        dataType:"json",
        approve:true,
        api:'yg_baijiaapp/userJournal/myZhuangBi',
        success:function(res){
            if(res.code==10000){
                var data=res.data;
                vm.userMoney=data.userMoney;
                //data.userJournalList.list.forEach(function(value,index){
                //    vm.recordList.push(value)
                //})
                if(data.userJournalList.list.length>0){
                    // 加载数据
                    loading = false;
                    data.userJournalList.list.forEach(function(value,index){
                        vm.recordList.push(value)
                    })
                }else{
                    $(document.body).destroyInfinite();
                }

            }else{

            }
        }

    })
}

var loading = false;
//滚动加载信息
function infiniteSroll(){
    console.log(111)
    $("body").infinite().on("infinite", function () {
        if (loading) return;
        loading=true;
        pageNum++;

        $('.weui-infinite-scroll-box').show();
        setTimeout(function () {
            loading = false;
            $('.weui-infinite-scroll-box').hide();
            getCashInfo();
        }, 1500);   //模拟延迟
        console.log(pageNum)
    });
}
